package com.welsy.newsmgt.command
{
	import com.adobe.cairngorm.commands.Command;
	import mx.rpc.IResponder;
	import com.welsy.util.NamespaceLocator;
	import com.adobe.cairngorm.control.CairngormEvent;	
	import mx.rpc.events.ResultEvent;
	import com.welsy.newsmgt.business.RemoveNewsDelegate;
	import com.welsy.newsmgt.event.RemoveNewsEvent;
	import com.welsy.newsmgt.model.NewsMgtModelLocator;
	import mx.controls.Alert;
	
	
	public class RemoveNewsCommand implements Command, IResponder
	{
		
		public function execute(event : CairngormEvent):void {
			var delegate : RemoveNewsDelegate = new RemoveNewsDelegate(this);
			var removeEvent : RemoveNewsEvent = RemoveNewsEvent(event);
			
			delegate.removeNews(removeEvent.news);
		}
		
		public function result(event : Object) :void {
			var nmodel:NewsMgtModelLocator = NewsMgtModelLocator.getInstance()
			
			//parse the server result
			//TODO: if the removal was successful, clear the GUI
			nmodel.newsRemovalSucceeded = true;
			
			//Ask for the list update
			nmodel.newsList = null;
		}
		
		public function fault( event : Object ):void {
			//TODO: report the error
			Alert.show("RemoveNewsCommand.fault!");
		}
		
	}
}